var map,mposctl,vectors, geojson,markers,selectControl;
var selectedFeature;
//Init
map = new OpenLayers.Map('floor3');
layer = new OpenLayers.Layer.Image(
    "floor3",
    "floor3.jpg",
    new OpenLayers.Bounds(-1105.5,-290,1105.5,290),
    new OpenLayers.Size(2211,580)
);
map.addLayer(layer);
map.zoomToMaxExtent();
var featurecollection = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_92",
            "properties": {
                "name": "A.302",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -1073,
                            255
                        ],
                        [
                            -794,
                            254
                        ],
                        [
                            -794,
                            38
                        ],
                        [
                            -1068,
                            36
                        ],
                        [
                            -1073,
                            255
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_117",
            "properties": {
                "name": "Computer lab room",
                "description": "computers available for students usage"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -1069,
                            32
                        ],
                        [
                            -797,
                            33
                        ],
                        [
                            -797,
                            -179
                        ],
                        [
                            -1066,
                            -178
                        ],
                        [
                            -1065,
                            -178
                        ],
                        [
                            -1069,
                            32
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_139",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -675,
                            255
                        ],
                        [
                            -556,
                            254
                        ],
                        [
                            -557,
                            66
                        ],
                        [
                            -675,
                            66
                        ],
                        [
                            -675,
                            255
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_161",
            "properties": {
                "name": "Elevator_3",
                "description": "Elevator of floor 3"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -680,
                            -61
                        ],
                        [
                            -537,
                            -60
                        ],
                        [
                            -538,
                            -177
                        ],
                        [
                            -679,
                            -177
                        ],
                        [
                            -680,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_185",
            "properties": {
                "name": "A.303",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -551,
                            254
                        ],
                        [
                            -373,
                            253
                        ],
                        [
                            -372,
                            64
                        ],
                        [
                            -553,
                            65
                        ],
                        [
                            -551,
                            254
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_207",
            "properties": {
                "name": "A.313",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -534,
                            -60
                        ],
                        [
                            -340,
                            -61
                        ],
                        [
                            -340,
                            -173
                        ],
                        [
                            -533,
                            -176
                        ],
                        [
                            -534,
                            -60
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_231",
            "properties": {
                "name": "A.304",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -367,
                            254
                        ],
                        [
                            -188,
                            254
                        ],
                        [
                            -188,
                            66
                        ],
                        [
                            -367,
                            67
                        ],
                        [
                            -367,
                            254
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_253",
            "properties": {
                "name": "A.305",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -183,
                            253
                        ],
                        [
                            8,
                            253
                        ],
                        [
                            8,
                            65
                        ],
                        [
                            -182,
                            66
                        ],
                        [
                            -183,
                            253
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_277",
            "properties": {
                "name": "A.306",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            11,
                            254
                        ],
                        [
                            192,
                            253
                        ],
                        [
                            190,
                            67
                        ],
                        [
                            12,
                            65
                        ],
                        [
                            11,
                            254
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_299",
            "properties": {
                "name": "A.307",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            195,
                            254
                        ],
                        [
                            386,
                            252
                        ],
                        [
                            386,
                            65
                        ],
                        [
                            195,
                            65
                        ],
                        [
                            195,
                            254
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_323",
            "properties": {
                "name": "A.308",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            392,
                            253
                        ],
                        [
                            574,
                            253
                        ],
                        [
                            576,
                            65
                        ],
                        [
                            390,
                            66
                        ],
                        [
                            392,
                            253
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_345",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            580,
                            253
                        ],
                        [
                            678,
                            253
                        ],
                        [
                            680,
                            65
                        ],
                        [
                            582,
                            65
                        ],
                        [
                            580,
                            253
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_369",
            "properties": {
                "name": "A.309",
                "description": "Auditorium"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            841,
                            216
                        ],
                        [
                            1092,
                            215
                        ],
                        [
                            1093,
                            -176
                        ],
                        [
                            839,
                            -176
                        ],
                        [
                            841,
                            216
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_393",
            "properties": {
                "name": "Stair_3",
                "description": "Stair of Floor 3"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            678,
                            -186
                        ],
                        [
                            756,
                            -188
                        ],
                        [
                            758,
                            -258
                        ],
                        [
                            680,
                            -259
                        ],
                        [
                            678,
                            -186
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_415",
            "properties": {
                "name": "Elevator_3",
                "description": "Elevator of Floor 3"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            535,
                            -61
                        ],
                        [
                            679,
                            -60
                        ],
                        [
                            680,
                            -178
                        ],
                        [
                            533,
                            -178
                        ],
                        [
                            535,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_437",
            "properties": {
                "name": "WC",
                "description": "Restroom"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            345,
                            -60
                        ],
                        [
                            529,
                            -62
                        ],
                        [
                            528,
                            -177
                        ],
                        [
                            346,
                            -180
                        ],
                        [
                            345,
                            -60
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_461",
            "properties": {
                "name": "University Cinic",
                "description": "University medical treatment"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            117,
                            -61
                        ],
                        [
                            341,
                            -60
                        ],
                        [
                            342,
                            -176
                        ],
                        [
                            116,
                            -177
                        ],
                        [
                            117,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_483",
            "properties": {
                "name": "Server room",
                "description": "server room"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -110,
                            -61
                        ],
                        [
                            110,
                            -61
                        ],
                        [
                            111,
                            -176
                        ],
                        [
                            -108,
                            -178
                        ],
                        [
                            -110,
                            -61
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_507",
            "properties": {
                "name": "Computer Service center",
                "description": "controlling the computer system"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -336,
                            -62
                        ],
                        [
                            -115,
                            -61
                        ],
                        [
                            -115,
                            -176
                        ],
                        [
                            -336,
                            -176
                        ],
                        [
                            -336,
                            -62
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "OpenLayers.Feature.Vector_531",
            "properties": {
                "name": "Stair_3",
                "description": "Stair of Floor 3"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -748,
                            -185
                        ],
                        [
                            -686,
                            -186
                        ],
                        [
                            -686,
                            -255
                        ],
                        [
                            -748,
                            -256
                        ],
                        [
                            -748,
                            -185
                        ]
                    ]
                ]
            }
        }
    ]
}
geojson = new OpenLayers.Format.GeoJSON();
vectors = new OpenLayers.Layer.Vector();
selectControl= new OpenLayers.Control.SelectFeature(vectors,
    {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
map.addLayer(vectors);
vectors.addFeatures(geojson.read(featurecollection));
map.addControl(selectControl);
selectControl.activate();
function onPopupClose(){selectControl.unselect(selectedFeature);};
function onFeatureSelect(feature){
    selectedFeature = feature;
    popup = new OpenLayers.Popup.FramedCloud(feature.id + "pop", feature.geometry.getBounds().getCenterLonLat(),null,"<div style='font-size:.8em'>Room: " + feature.attributes.name + "<br />Description: " + feature.attributes.description + "</div>",null, true, onPopupClose);
    feature.popup = popup;
    map.addPopup(popup);
}
function onFeatureUnselect(feature){
    map.removePopup(feature.popup);
    feature.popup.destroy();
    feature.popup = null;
}
